package com.whty.cms.filewps.upload.service.impl;

import com.whty.cms.filewps.common.service.impl.BaseAbstractServiceImpl;
import com.whty.cms.filewps.upload.dao.TeamworkEditMapper;
import com.whty.cms.filewps.upload.dto.TeamworkEdit;
import com.whty.cms.filewps.upload.service.IEditService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;


@Service("editService")
public class EditServiceImpl extends BaseAbstractServiceImpl<TeamworkEdit> implements IEditService {

    @Autowired
    private TeamworkEditMapper teamworkEditMapper;

    @Override
    public void save(TeamworkEdit teamworkEdit) {
        teamworkEditMapper.insert(teamworkEdit);
    }

    @Override
    public List<TeamworkEdit> selectAll(TeamworkEdit teamworkEdit) {
        Example example=new Example(TeamworkEdit.class);//要查询的表对应的实体类
        Example.Criteria criteria=example.createCriteria();//创建查询标准
        List<String> list = new ArrayList<>();
        list.add(teamworkEdit.getUserId());
        if (!"everyone".equals(teamworkEdit.getUserId())) {
            list.add("everyone");
        }
        criteria.andIn("userId",list);
        criteria.andEqualTo("fid",teamworkEdit.getFid());
        if (StringUtils.isNotBlank(teamworkEdit.getType())) {
            criteria.andEqualTo("type", teamworkEdit.getType());
        }
//        example.setOrderByClause("create_time desc");
        return teamworkEditMapper.selectByExample(example);
    }

    @Override
    public List<TeamworkEdit>  selectRes(TeamworkEdit teamworkEdit) {
        Example example=new Example(TeamworkEdit.class);//要查询的表对应的实体类
        Example.Criteria criteria=example.createCriteria();//创建查询标准
        criteria.andEqualTo("userId",teamworkEdit.getUserId());
        criteria.andEqualTo("fid",teamworkEdit.getFid());
        return teamworkEditMapper.selectByExample(example);
    }
}
